/*!
 *  \file       HighPassFilterGenerator.cpp
 *  \brief      Implementazione della classe \c HighPassFilterGenerator
 *  \author     Davide Scola <S2299453@studenti.unige.it>
 *  \author	Minetti Alberto <S3064777@studenti.unige.it>
 *  \version    1.0
 *
 */
#include <vector>
#include <complex>
#include "IFilterGenerator.hpp"
#include "HighPassFilterGenerator.hpp"

using namespace std;


/*!
 *  \brief	Costruttore della classe \c HighPassFilterGenerator
 *  \param[in]	input		fft di input
 *
 *  \see	HighPassFilterGenerator< tType >::HighPassFilterGenerator( HighPassFilterGenerator< tType > const& other )
 */
template< class tType >
HighPassFilterGenerator< tType >::HighPassFilterGenerator( std::vector< std::complex< tType > > &input )
    : iIndex_( 0 ),
      inputSize_( (&input)->size( ) ),
      cutoffIndex_( 1 )
{
  for( unsigned long int i = 2; i < this->inputSize_; ++i)
    if( input[i].real() > input[ this->cutoffIndex_ ].real() )
      this->cutoffIndex_ = i;
}

/*!
 *  \brief      Costruttore di copia della classe \c HighPassFilterGenerator
 *  \param[in]	other	generatore da copiare
 *
 *  \see	HighPassFilterGenerator< tType >::HighPassFilterGenerator( std::vector< std::complex< tType > > &input )
 */
template< class tType >
HighPassFilterGenerator< tType >::HighPassFilterGenerator( HighPassFilterGenerator< tType > const& other )
    : iIndex_( (&other)->iIndex_ ),
      inputSize_( (&other)->inputSize_ ),
      cutoffIndex_( (&other)->cutoffIndex_ )
{
}


/*!
 *  \brief      Operatore di assegnazione della classe \c HighPassFilterGenerator
 */
template < typename tType > HighPassFilterGenerator< tType >&
HighPassFilterGenerator< tType >::operator=( const HighPassFilterGenerator& other )
{
   if (this == &other) {
       return *this;
   }
   
   this->iIndex_ = (&other)->iIndex_;
   this->inputSize_ = (&other)->inputSize_;
   this->cutoffIndex_ = (&other)->cutoffIndex_;
   
   return *this;
}


/*!
 *  \brief      Generatore del rumore
 *  \return	ritorna il valore corrente del segnale perturbato con una poissoniana
 */
template< class tType > std::complex< tType >
HighPassFilterGenerator< tType >::operator() ( std::complex< tType > currPoint )
{
  unsigned long int swap = this->iIndex_++;
  
  if( this->iIndex_ >= this->inputSize_ )
    this->iIndex_ = 0;
  
  return ( ( swap > 0 && swap <= this->cutoffIndex_ )						||
	    ( swap >= ( this->inputSize_ - this->cutoffIndex_ ) && swap < this->inputSize_ ) )	?
	    std::complex< tType >( 0 )								:
	    currPoint;
}
